﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{
	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using System.Runtime.Serialization;
	using System.Text;

	/// <summary>
	/// A Data Transfer Object (DTO) that represents a rate limit object 
	/// from twitter.
	/// </summary>
	/// <remarks>
	///		<para>
	///			It represents the &quot;rate_limit&quot; element/object in both the xml and 
	///			json portions of the REST responses. 
	///		</para>
	/// </remarks>
	[DataContract(Name="rate_status")]
	public class RateStatus : TwitterError
	{
		private string resetTimeString = "";
		private DateTime resetTime = DateTime.MinValue;

		/// <summary>
		///		Gets or sets the remaining hits left for the current duration.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;remaining_hits&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "remaining_hits")]
		public int? RemainingHits { get; set; }

		/// <summary>
		///		Gets or sets the hourly rate limit.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;hourly_limit&quot;.
		///			The number of hits allowed per hour.
		///		</para>
		/// </remarks>
		[DataMember(Name = "hourly_limit")]
		public int? HourlyLimit { get; set; }

		/// <summary>
		///		Gets or sets the &quot;reset time in seconds&quot;
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;hourly_limit&quot;.
		///			The number of seconds remaining for the reset time. 
		///		</para>
		/// </remarks>
		[DataMember(Name = "reset_time_in_seconds")]
		public int? ResetTimeInSeconds { get; set; }

		/// <summary>
		/// Gets or sets <see cref="System.String"/> value of the Date/Time for the reset.
		/// </summary>
		/// <remarks>
		///		<para>
		///		The string format from twitter is &quot;ddd MMM dd HH:mm:ss zzzz yyyy&quot;
		///		</para>
		/// </remarks>
		[DataMember(Name="reset_time")]
		public string ResetTimeString
		{
			get { return this.resetTimeString; }
			set
			{
				this.resetTimeString = value;
				if (!string.IsNullOrEmpty(value))
				{
					this.resetTime = DateTime.ParseExact(
						value, Status.TimeFormat,
						 CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
				}
			}
		}

		/// <summary>
		/// Gets or sets <see cref="System.DateTime"/> value of the ResetTimeString value from  
		/// twitter, if it can be parsed. 
		/// </summary>
		public DateTime ResetTime
		{
			get { return this.resetTime; }
			set {
				this.resetTime = value;
				this.resetTimeString = value.ToString(Status.TimeFormat);
			}
		}

	}
}
